#include "stdafx.h"

Animation::Animation(const std::wstring & picname, int num, double interval, int x, int y)
{
	this->picname = picname;
	this->num = num;
	this->interval = interval;
	this->x = x;
	this->y = y;

	picSet = new Image*[num];
	for (wchar_t i = '1'; i < '1' + num; i++)
	{
		picSet[i - '1'] = ImageMgr::getInstance()->getImageFromName(picname + i + L".png");
	}
	width = picSet[0]->GetWidth();
	height = picSet[0]->GetHeight();
}

Animation::~Animation()
{
	delete[] picSet;
}

void Animation::update(double dtime)
{
	time += dtime;
	if (time >= interval)
	{
		curpic++;
		time -= interval;
	}
}

void Animation::draw(Graphics * graphics)
{
	graphics->DrawImage(picSet[curpic], x - width / 2, y - height / 2);
}

bool Animation::finished()
{
	return curpic >= num;
}